//二叉树最大和
public class TreeMaxSum {

}
class TreeMaxSumSolution {
    int ret = Integer.MIN_VALUE;
    public int maxPathSum(TreeNode root) {
        dfs(root);
        return ret;
    }
    int dfs(TreeNode root){
        if(root==null)return 0;
        int left = Math.max(0,dfs(root.left));
        int right = Math.max(0,dfs(root.right));
        ret = Math.max(ret,left+right+root.val);
        return root.val+Math.max(left,right);
    }
}

 class TreeNode {
     int val;
     TreeNode left;
     TreeNode right;
     TreeNode() {}
     TreeNode(int val) { this.val = val; }
     TreeNode(int val, TreeNode left, TreeNode right) {
         this.val = val;
         this.left = left;
         this.right = right;
     }
 }
